package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类模块
 */
@RestController
@RequestMapping("/admin/category")
@Api("分类相关接口")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增分类")
    public Result<String> addClassification(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类：{}", categoryDTO);
        return categoryService.addClassification(categoryDTO);
    }

    /**
     * 分类分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分类分页查询")
    public Result page(CategoryPageQueryDTO dto){
        log.info("分类分页查询：{}", dto);
        return categoryService.page(dto);
    }

    /**
     * 根据ID删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "根据ID删除分类")
    public Result deleteClassificationById(Long id){
        log.info("根据ID删除分类：{}", id);
        return categoryService.deleteClassificationById(id);
    }

    /**
     * 修改分类
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改分类")
    public Result modifyClassification(@RequestBody CategoryDTO dto){
        log.info("修改分类：{}", dto);
        return categoryService.modifyClassification(dto);
    }

    /**
     * 分类启用禁用
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "启用禁用")
    @PostMapping("/status/{status}")
    public Result updateCategoryStatus(@PathVariable Integer status, Long id){
        log.info("分类启用禁用：{}", id,status);
        return categoryService.updateCategoryStatus(status,id);
    }

    /**
     * 类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = (List<Category>) categoryService.queryList(type);
        return Result.success(list);
    }
}
